package net.factoryOpen.quickfactory.manufacturing.ord.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import net.factoryOpen.quickfactory.manufacturing.ord.domain.OrdSoComplain;
import net.factoryOpen.quickfactory.manufacturing.ord.service.IOrdSoComplainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单客诉登记Controller
 *
 * @author factoryOpen
 * @date 2025-06-01
 * @version 1.0.0-draft.0
 */
@RestController
@RequestMapping("/ord/soComplain")
public class OrdSoComplainController extends BaseController
{
    @Autowired
    private IOrdSoComplainService ordSoComplainService;

    /**
     * 查询订单客诉登记列表
     */
    //@PreAuthorize("@ss.hasPermi('ord:soComplain:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrdSoComplain ordSoComplain)
    {
        startPage();
        List<OrdSoComplain> list = ordSoComplainService.selectOrdSoComplainList(ordSoComplain);
        return getDataTable(list);
    }

    /**
     * 导出订单客诉登记列表
     */
    //@PreAuthorize("@ss.hasPermi('ord:soComplain:export')")
    @Log(title = "订单客诉登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrdSoComplain ordSoComplain)
    {
        List<OrdSoComplain> list = ordSoComplainService.selectOrdSoComplainList(ordSoComplain);
        ExcelUtil<OrdSoComplain> util = new ExcelUtil<OrdSoComplain>(OrdSoComplain.class);
        util.exportExcel(response, list, "订单客诉登记数据");
    }

    /**
     * 获取订单客诉登记详细信息
     */
    //@PreAuthorize("@ss.hasPermi('ord:soComplain:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ordSoComplainService.selectOrdSoComplainById(id));
    }

    /**
     * 新增订单客诉登记
     */
    //@PreAuthorize("@ss.hasPermi('ord:soComplain:add')")
    @Log(title = "订单客诉登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrdSoComplain ordSoComplain)
    {
        AjaxResult ar = null;
        try{
           int ret = ordSoComplainService.insertOrdSoComplain(ordSoComplain);
           if (ret > 0){
               ar = AjaxResult.success("操作成功：[新增]1条数据！");
           }
           else{
               ar = AjaxResult.error(ret, "操作失败：[新增]0条数据！");
           }
        }
        catch (Exception e){
            e.printStackTrace();
            ar = AjaxResult.error("操作异常："+e.getMessage());
        }
        return ar;
    }

    /**
     * 修改订单客诉登记
     */
    //@PreAuthorize("@ss.hasPermi('ord:soComplain:edit')")
    @Log(title = "订单客诉登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrdSoComplain ordSoComplain)
    {
        AjaxResult ar = null;
        try{
            int ret = ordSoComplainService.updateOrdSoComplain(ordSoComplain);
            if (ret > 0){
                ar = AjaxResult.success("操作成功：[修改]"+ret+"条数据！");
            }
            else{
                ar = AjaxResult.error(ret, "操作失败：[修改]0条数据！");
            }
        }
        catch (Exception e){
            e.printStackTrace();
            ar = AjaxResult.error("操作异常："+e.getMessage());
        }
        return ar;
    }

    /**
     * 删除订单客诉登记
     */
    //@PreAuthorize("@ss.hasPermi('ord:soComplain:remove')")
    @Log(title = "订单客诉登记", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        AjaxResult ar = null;
        try{
            int ret = ordSoComplainService.deleteOrdSoComplainByIds(ids);
            if (ret > 0){
                ar = AjaxResult.success("操作成功：[删除]"+ret+"条数据！");
            }
            else{
                ar = AjaxResult.error(ret, "操作失败：[删除]0条数据！");
            }
        }
        catch (Exception e){
            e.printStackTrace();
            ar = AjaxResult.error("操作异常："+e.getMessage());
        }
        return ar;
    }

    /**
     * 客诉
     */
    //@PreAuthorize("@ss.hasPermi('ord:soComplain:complainReg')")
    @Log(title = "客诉", businessType = BusinessType.OTHER)
    @PutMapping("/complainReg")
    public AjaxResult complainReg(@RequestBody OrdSoComplain ordSoComplain)
    {
        AjaxResult ar = null;
        try{
            ordSoComplainService.complainReg(ordSoComplain);
            ar = AjaxResult.success("操作成功：[客诉]"+"执行完成！");
        }
        catch (Exception e){
            e.printStackTrace();
            ar = AjaxResult.error("操作异常："+e.getMessage());
        }
        return ar;
    }

}
